﻿
CREATE PROCEDURE dbo.s_VerItem_Normailze
	@ParentID int = 0
AS
DECLARE cur CURSOR LOCAL FORWARD_ONLY STATIC
FOR SELECT ID,TabIndex FROM t_Verification WHERE ParentID = @ParentID ORDER BY TabIndex

DECLARE @ID int,@Counter int,@TabIndex int
OPEN cur

SET @Counter = 1

FETCH NEXT FROM cur INTO @ID,@TabIndex
WHILE @@FETCH_STATUS = 0 BEGIN

	UPDATE t_Verification
	SET TabIndex = -@Counter
	WHERE ID = @ID

	SET @Counter = @Counter + 1

	EXEC s_VerItem_Normailze @ID

	FETCH NEXT FROM cur INTO @ID,@TabIndex
END

CLOSE cur
DEALLOCATE cur

